/**
 * @file      ac_tlm_router.cpp
 * @author    Rafael Ghussn Cano
 * 
 * @brief     Implements a ac_tlm router.
 */

//////////////////////////////////////////////////////////////////////////////

#ifndef AC_TLM_ROUTER_H_
#define AC_TLM_ROUTER_H_

//////////////////////////////////////////////////////////////////////////////

// Standard includes
// SystemC includes
#include <systemc>
// ArchC includes
#include "ac_tlm_protocol.H"

#include  "ac_tlm_port.H"

//////////////////////////////////////////////////////////////////////////////

// using statements
using tlm::tlm_transport_if;

//////////////////////////////////////////////////////////////////////////////

/// Namespace to isolate router from ArchC
namespace user
{

/// A TLM router
class ac_tlm_router :
  public sc_module,
  public ac_tlm_transport_if // Using ArchC TLM protocol
{
public:

  /// Exposed port with ArchC interface
  sc_export< ac_tlm_transport_if > target_export;
  //DM_port1 = porta da memoria
  //DM_port2 = porta do contador
  //DM_port3 = porta do periferico que controla os locks
  //DM_port4 = porta do periferico bit_shifter
  //DM_port5 = porta do periferico bit_counter
  ac_tlm_port DM_port1, DM_port2, DM_port3, DM_port4, DM_port5;
    
  /**
   * Implementation of TLM transport method that
   * handle packets of the protocol doing apropriate actions.
   * This method must be implemented (required by SystemC TLM).
   * @param request is a received request packet
   * @return A response packet to be send
  */
  ac_tlm_rsp transport( const ac_tlm_req &request ) {
    if(request.addr < 5*1024*1024){
      return DM_port1->transport(request);
    }else if(request.addr == 5*1024*1024){
      return DM_port2->transport(request);
    }else if(request.addr <= 5*1024*1024+8){
      return DM_port4->transport(request);
    }else if(request.addr <= 5*1024*1024+16){
      return DM_port5->transport(request);
    }else{
      return DM_port3->transport(request);
    } 
 }

  /** 
   * Default constructor.
   */
  ac_tlm_router( sc_module_name module_name );

};

};

#endif //AC_TLM_ROUTER_H_
